﻿using Microsoft.Xna.Framework;
using SomeGame.Actors.Components.State;

namespace SomeGame.Actors.Components.Health {

	public class ZombieHealth : ActorComponent {

		private readonly ZombieStateMachine StateMachine;
	    private readonly int MaxHealth;
		private int CurrentHealth;

		public ZombieHealth(ZombieStateMachine stateMachine, int maxHealth = 30) {
			StateMachine = stateMachine;
			MaxHealth = maxHealth;
			CurrentHealth = MaxHealth;
		}

	    public void ReduceHealth(int amount) {
	        CurrentHealth -= amount;
	        if (CurrentHealth > 0) { // Not dead yet.
	            StateMachine.SetCurrentState(ZombieStateMachine.State.InPain);
	        }
	    }

        public override void Update(GameTime gameTime, bool parallax) {
            if (CurrentHealth <= -30 // Gibbed.
                && StateMachine.CurrentState != ZombieStateMachine.State.Dead
                && StateMachine.CurrentState != ZombieStateMachine.State.Dying
                && StateMachine.CurrentState != ZombieStateMachine.State.Gibbed
                && StateMachine.CurrentState != ZombieStateMachine.State.Goo) {
                StateMachine.SetCurrentState(ZombieStateMachine.State.Gibbed);
            } else if (CurrentHealth <= 0 // Dying
                && StateMachine.CurrentState != ZombieStateMachine.State.Dead
                && StateMachine.CurrentState != ZombieStateMachine.State.Dying
                && StateMachine.CurrentState != ZombieStateMachine.State.Gibbed
                && StateMachine.CurrentState != ZombieStateMachine.State.Goo) {
				StateMachine.SetCurrentState(ZombieStateMachine.State.Dying);
			}
		}

	}

}